package com.zlsy.thread.createthread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author zhouliang
 * @date 2020/03/17
 **/
public class CompareCreateThreadByTwoMethod {


    public static void main(String[] args) {
        //runnable 接口运行可以放到线程池里面，减少线程创建和销毁的开销
        ByImplRunnable byImplRunnable = new ByImplRunnable();
        ExecutorService executorService = Executors.newFixedThreadPool(2);
        executorService.execute(byImplRunnable);
        executorService.shutdown();

        //thread 运行: 没法借助工具类
        new ByExtendThread().start();
    }

}

class ByImplRunnable implements Runnable {

    @Override
    public void run() {
        System.out.println(1);
    }
}

class ByExtendThread extends Thread {
    @Override
    public void run() {
        System.out.println(2);
    }
}